package util

import (
	"github.com/Chain-Zhang/pinyin"
	"ubt-rbac-service/internal/core/logger"
	"strings"
)

// GetPinyin 将汉字转换为拼音
func GetPinyin(chain string) (quanPin, jianPin string) {
	quanPin, err := pinyin.New(chain).Split("").Mode(pinyin.InitialsInCapitals).Convert()
	if err != nil {
		logger.Error("汉字转换拼音失败。" + err.Error())
	}
	for i := 0; i < len(quanPin); i++ {
		// 获取字母的ASCII码，是否为大写A~Z(65~90)，如果是则取出来
		if 64 < quanPin[i] && quanPin[i] < 91 {
			jianPin += string(quanPin[i])
		}
	}
	quanPin = strings.ToLower(quanPin)
	jianPin = strings.ToLower(jianPin)
	return quanPin, jianPin
}
